package com.example.review.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.review.entity.Emp;
import com.example.review.service.EmpService;
import com.example.review.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Api(value = "员工接口类") ：接口文档的说明
 * @ApiOperation(value = "分页查询员工信息")：接口文档中方法的说明
 * @ApiParam(value = "当前页码",required = true)：接口文档方法中参数的说明
 *              required = true代表此参数是必填项
 */
@Api(value = "员工接口类")
@RestController
@RequestMapping("/emp")
public class EmpController {

    @Resource
    private EmpService empService;

    /**
     * 分页查询所有员工信息
     */
    @PostMapping("getAll/{currentPage}/{pageSize}")
    @ApiOperation(value = "分页查询员工信息")
    public Result<IPage<Emp>> getAll(@ApiParam(value = "当前页码",required = true) @PathVariable Integer currentPage,
                                     @ApiParam(value = "每页的信息条数",required = true) @PathVariable Integer pageSize){
        return empService.listByPage(currentPage, pageSize);
    }


    /**
     * 根据id删除员工
     */
    @DeleteMapping("delEmp/{empno}")
    @ApiOperation(value = "根据员工id删除员工")
    public Result delEmp(@ApiParam(value = "员工编号",required = true)@PathVariable Integer empno){
         return new Result(200,"操作成功",empService.removeById(empno));
    }
}
